#!/bin/tcsh -ef
#############################################################################
#                                                                           #
# Title: Run refinement			                          		#
#                                                                           #
# (C) 2dx.org, GNU Plublic License.                                         #
#                                                                           #
# Created..........: 29/07/2016                                             #
# Last Modification: 29/07/2016                                             #
# Author...........: 2dx.org                                                #
#                                                                           #
#############################################################################
#
# SORTORDER: 8
#
#
# MANUAL: This script launches a refinement in single-particle mode using the particles extracted from the 2D crystal images, initialized with the alignment parameters obtained in the pre-refinement.
#
# MANUAL: This script is based on the frealign_run_refinement script distributed with FREALIGN v9.11, which was modified to support FREALIGN launching from an arbitrary directory.
#
# DISPLAY: SPR_DIR
# DISPLAY: SPR_REFINE_DIR
#
#$end_local_vars
#
set bin_2dx = ""
set proc_2dx = ""
set dir_frealign = ""

set scriptname = RunRefineFREALIGN

set ccp4_setup = 'y'
source ${proc_2dx}/initialize
#

set SPR_DIR = ""
set SPR_REFINE_DIR = ""

set SPR_REFINE_DIR = ${SPR_DIR}/FREALIGN/${SPR_REFINE_DIR}/

#$end_vars

if ( -e LOGS/${scriptname}.results ) then
	mv LOGS/${scriptname}.results LOGS/${scriptname}.results.old
endif

# There's some issue with ${PWD} and {$OLDPWD} in csh, so just to be safe:
set SAVEPATH = ${PWD}

cd ${SPR_REFINE_DIR}

${dir_frealign}/bin/frealign_run_refine

cd ${SAVEPATH}

echo ":: "
echo ":: Refinement with FREALIGN has been launched."
echo ":: This may take some time to complete."
echo ":: For detailed information please check ${SPR_REFINE_DIR}/frealign.log"
echo ":: "
